import fs from 'fs';
import { CronJob } from 'cron';
import path from 'path';
import { TMP_PATH } from '../../config/env';

export const clearTmpJob = CronJob.from({
    cronTime: '* * 6 * * *',
    onTick: function () {
        fs.readdir(TMP_PATH, (err, files) => {
            if (err) return;

            for (const file of files) {
                fs.unlink(path.join(TMP_PATH, file), (err) => {
                    if (err) return;
                    console.log(`Deleted ${file}`);
                });
            }
        })
    }
});
